home *** CD-ROM | disk | FTP | other *** search
- Path: crchh327.rich.bnr.ca!jobell
- From: jobell@bnr.ca (Bret Bieghler)
- Newsgroups: comp.object,comp.lang.c++
- Subject: Defining Object Associations
- Date: 26 Mar 1996 18:58:04 GMT
- Organization: Nortel Technologies
- Message-ID: <4j9ens$jtq@crchh327.rich.bnr.ca>
- NNTP-Posting-Host: crchhd4a.rich.bnr.ca
-
- Are there any preferences to defining object associations in
- C++. My working system has several objects that must all
- communicate with each other, and many objects have to be in
- existence before creating another certain type.
-
- For example, a LoggingManager object and DisplayManager object
- must be most constructed before creating a CommandDispatcher.
- Yet the CommandDispatcher also requires that an EventManager
- has been created, etc.
-
- So I have code that goes along creating these objects, and
- when I create the CommandDispatcher I say,
-
- CommandDispatcher* CD = new CommandDispatcher(LM, DM, EM);
-
- etc.
-
- But whenever the CommandDispatcher needs to talk a different
- type of object, I have to add it to the constructor and also
- ensure that the new object has all of its requirements
- fulfilled before created the CommandDispatcher.
-
- This presents a headache because I have to worry about the
- order in which I create all of these things, and my code
- is rearranged a lot.
-
- So what I would like is a global container of references to
- pointers that I can attach to each object as I declare its
- pointer (before I new it). Then when I'm ready to new it
- I pass in all of the references (via a single struct or
- some sort) and everybody knows about everybody else.
-
- So my question is, what is the preferred method of association?
- What is the best of way of letting an object know about another
- object? Pointers that are declared in the constructor (requiring
- creation dependicies), or setDisplayManager(DM) type methods that
- allow you to set an object when you are reading (but since it
- is a "construction" I prefer it to be in the constructor).
-
- Thanks for any suggestions you may have.
-
- Regards,
-
- Joseph A. Bell
- Nortel Technologies
-
- --
- Joseph A. Bell (NOT Bret Bieghler) jobell@bnr.ca
- Northern Telecom / Bell-Northern Research
- "What? Evacuate now, in our moment of triumph? Surely you overestimate their chances."
-